﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OgilvyOne.BLL;
using System.Text;
using System.Xml;

public partial class allergy_nestle_toal : System.Web.UI.Page
{
    private string total;
    protected void Page_Load(object sender, EventArgs e)
    {
        string strFrom = Request.QueryString["from"];
        string strCallBack = Request.QueryString["callback"];
        DataTable dt = BLLArticleInfo.flash();
        foreach (DataRow row in dt.Rows)
        {
            total = row["count"].ToString();
        }
        if (!string.IsNullOrEmpty(strFrom))
        {
            StringBuilder sb = new StringBuilder();
            Response.ContentType = "text/javascript";
            Response.ContentEncoding = Encoding.UTF8;
            if (strFrom == "baidu" && !string.IsNullOrEmpty(strCallBack))
            {
                //bd_jsonp_uls34l({
                //      "success" : "true",
                //    "message" : "",
                //      "result" : {
                //             "data" : 23546
                //   }
                //})
                if (!string.IsNullOrEmpty(total))
                {
                    sb.Append(strCallBack + "({");
                    sb.Append("\"success\" : \"true\",");
                    sb.Append("\"message\" : \"\",");
                    sb.Append("\"result\" : {");
                    sb.Append("\"data\" : " + total + "");
                    sb.Append("}");
                    sb.Append("})");
                }
            }
            else
            {
                sb.Append(strCallBack + "({");
                sb.Append("\"success\" : \"flase\",");
                sb.Append("\"message\" : \"请求参数错误\"");
                sb.Append("})");
            }

            Response.Write(sb.ToString());
            Response.End();
        }
        else
        {
            //生成xml文档
            Response.Clear();
            Encoding gb2312 = Encoding.GetEncoding("UTF-8");
            Response.ContentEncoding = gb2312;
            XmlDocument doc = new XmlDocument();
            XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
            doc.AppendChild(decl);

            //创建根节点   data
            XmlElement element = doc.CreateElement("result");
            doc.AppendChild(element);

            XmlElement data = doc.CreateElement("data");
            data.InnerText = total.ToString();
            element.AppendChild(data);

            //向页面输出xml文档
            Response.Write(doc.OuterXml);
            Response.End();
 
        }
    }
}
